package operation.chef;

import zy.Dish;
import zy.Warehouse;

import java.util.Random;
import java.util.Scanner;

/*
 *@Student 张策
 */
public class chef2 implements Ioperation {
    Scanner scanner=new Scanner(System.in);
    @Override
    public void work(Warehouse warehouse) {
        while (true) {
            System.out.println("---------菜单模块-------");
            System.out.println("1:查看菜单");
            System.out.println("2:修改菜单");
            System.out.println("3:删除特色菜");
            System.out.println("4:增加特色菜");
            System.out.println("5:返回上一级");
            System.out.println();
            System.out.println("请输入您的选择:");
            String ch;
            int choice;
            while (true){
                 ch=scanner.nextLine();
                if(warehouse.isNum(ch)&&Integer.parseInt(ch)<=5&&Integer.parseInt(ch)>=1){
                    choice=Integer.parseInt(ch);
                    break;
                }else {
                    System.out.println("数字不合理，请重新输入");
                }
            }

            switch (choice) {
                case 1:
                    warehouse.show();
                    break;
                case 2:
                    warehouse.setDishes();
                    break;
                case 3:
                    RemoveDish(warehouse);
                    break;
                case 4:
                    AddDish(warehouse);
                    break;
                case 5:
                    return;

            }
        }
    }
    //删除特色菜！
    private void RemoveDish(Warehouse warehouse){
        warehouse.show();
        System.out.println("请输入要删除的菜名");
        String name=scanner.nextLine();
        while (!warehouse.nameBool(name)){
            System.out.println("不存在该菜品，请重新输入");
            name=scanner.nextLine();
        }
        warehouse.dishes.remove(warehouse.xDish(name));
        System.out.println("删除成功！");
        //遍历菜单数组，更新ID
        for (int i = 0; i < warehouse.dishes.size(); i++) {
            warehouse.dishes.get(i).setId(i+1);
        }
    }
    //增加特色菜!
    private void AddDish(Warehouse warehouse){
        warehouse.show();
        System.out.println("----------新增菜单---------");
//        System.out.println("请输入ID:");
//        String i=scanner.nextLine();
//        while (!warehouse.isNum(i)){
//            System.out.println("输入错误，请重新输入");
//            i=scanner.nextLine();
//        }
//        int id=Integer.parseInt(i);
        System.out.println("请输入菜名:");
        String name=scanner.nextLine();
        System.out.println("请输入菜价");
        double price=scanner.nextDouble();
        scanner.nextLine();
        System.out.println("请输入描述");
        String desc=scanner.nextLine();
        warehouse.dishes.add(new Dish(name,price,desc));
        System.out.println("增加成功");
    }
}
